package com.example.administrator.leddemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import com.cbtService.AndroidSDK.LedService;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    //声明
    private ImageButton b1,b2,b3,b4;
    public static boolean iflog1=true;
    public static boolean iflog2=true;
    public static boolean iflog3=true;
    public static boolean iflog4=true;
    LedService led;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(ImageButton)findViewById(R.id.imageButton);
        b2=(ImageButton)findViewById(R.id.imageButton2);
        b3=(ImageButton)findViewById(R.id.imageButton3);
        b4=(ImageButton)findViewById(R.id.imageButton4);
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
        b3.setOnClickListener(this);
        b4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
                case R.id.imageButton:
                    System.out.println("led1 按下");
                    if(iflog1) {
                        //调用底层接口
                        led._setLedState(0,1);
                        b1.setImageResource(R.drawable.ledon);
                        iflog1 = false;
                    }else {
                        led._setLedState(0,0);
                        b1.setImageResource(R.drawable.ledoff);
                        iflog1=true;
                    }
                    break;
            case R.id.imageButton2:
                System.out.println("led1 按下");
                if(iflog2) {
                    led._setLedState(1,1);
                    b2.setImageResource(R.drawable.ledon);
                    iflog2 = false;
                }else {
                    led._setLedState(1,0);
                    b2.setImageResource(R.drawable.ledoff);
                    iflog2=true;
                }
                break;
            case R.id.imageButton3:
                System.out.println("led1 按下");
                if(iflog3) {
                    led._setLedState(2,1);
                    b3.setImageResource(R.drawable.ledon);
                    iflog3 = false;
                }else {
                    led._setLedState(2,0);
                    b3.setImageResource(R.drawable.ledoff);
                    iflog3=true;
                }

                break;
            case R.id.imageButton4:
                System.out.println("led1 按下");
                if(iflog4) {
                    led._setLedState(3,1);
                    b4.setImageResource(R.drawable.ledon);
                    iflog4 = false;
                }else {
                    led._setLedState(3,0);
                    b4.setImageResource(R.drawable.ledoff);
                    iflog4=true;
                }
                break;
        }
    }
}
